﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bzure.Common.Core;
using Bzure.Common.Data;
using Bzure.Security.Principal;

namespace Bzure.Apps.Security
{
    /// <summary>
    /// 自定义用户组
    /// </summary>
    public class UserGroup : Entity, IPostEntity, IAwarded,IBlock
    {
        public UserGroup()
        {
            this.ID = string.Empty;
            this.Name = string.Empty;
            this.Description = string.Empty;
            this.State = 0;
            this.BlockName = string.Empty;
        }
        public string ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
        public int State { get; set; }
        /// <summary>
        /// 所有人用户名
        /// </summary>
        public string OwnerName { get; set; }
        //组类型
        public string BlockName { get; set; }
        public EntityPostRequest ToUpdateRequest()
        {
            EntityPostRequest OrderRequest;
            if (this.IsPersisted())
            {
                OrderRequest = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Update)
                {
                    Entity = this
                };

                OrderRequest.AppendConditionMap(this.ID, () => this.ID);
            }
            else
            {
                OrderRequest = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Create)
                {
                    Entity = this
                };

                OrderRequest.AppendFieldMap(this.ID, () => this.ID);

            }
            OrderRequest.AppendFieldMap(this.Name, () => this.Name);
            OrderRequest.AppendFieldMap(this.Description, () => this.Description);
            OrderRequest.AppendFieldMap(this.State, () => this.State);
            OrderRequest.AppendFieldMap(this.OwnerName, () => this.OwnerName);
            OrderRequest.AppendFieldMap(this.BlockName, () => this.BlockName);
            return OrderRequest;
        }
        public EntityPostRequest ToDeleteRequest()
        {
            EntityPostRequest post = new EntityPostRequest(EntityPostRequest.EntityPostMethod.Delete)
            {
                Entity = this
            };
            post.AppendConditionMap(this.ID, () => this.ID);
            return post;
        }
    }
}
